import { http } from "@/utils/http";
import type {
  NotificationSettings,
  NotificationSettingsUpdateParams,
  DoNotDisturbParams
} from "@/types/notification-settings";

/** 统一响应格式 */
export interface ApiResponse<T = any> {
  /** 状态码 */
  code: number;
  /** 响应消息 */
  message: string;
  /** 响应数据 */
  data?: T;
}

/**
 * 获取当前用户的通知设置
 */
export const getNotificationSettingsApi = () => {
  return http.request<ApiResponse<NotificationSettings>>(
    "get",
    "/api/notification-settings"
  );
};

/**
 * 更新当前用户的通知设置
 * @param params 通知设置更新参数
 */
export const updateNotificationSettingsApi = (
  params: NotificationSettingsUpdateParams
) => {
  return http.request<ApiResponse>("put", "/api/notification-settings", {
    data: params
  });
};

/**
 * 重置通知设置为默认值
 */
export const resetNotificationSettingsApi = () => {
  return http.request<ApiResponse>("post", "/api/notification-settings/reset");
};

/**
 * 一键开启所有通知
 */
export const enableAllNotificationsApi = () => {
  return http.request<ApiResponse>(
    "post",
    "/api/notification-settings/enable-all"
  );
};

/**
 * 一键关闭所有通知
 */
export const disableAllNotificationsApi = () => {
  return http.request<ApiResponse>(
    "post",
    "/api/notification-settings/disable-all"
  );
};

/**
 * 开启/关闭免打扰模式
 * @param params 免打扰设置参数
 */
export const setDoNotDisturbApi = (params: DoNotDisturbParams) => {
  return http.request<ApiResponse>(
    "post",
    "/api/notification-settings/do-not-disturb",
    { params }
  );
};
